package com.kaifamiao.date1110;

import java.util.Objects;

public class Dog {

	private String name;
	private int age;
	
	public Dog(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}
	
	@Override
	public boolean equals( Object another ) {
		if( this == another ) {
			return true ;
		}
		
		if( this.getClass() != another.getClass() ) {
			return false ;
		}
		
		Dog d = (Dog) another ;
		// return ( name == d.name || ( name != null && name.equals( d.name ) ) ) && age == d.age ;
		return Objects.equals( name , d.name ) && age == d.age ;
	}
	
	@Override
	public int hashCode() {
		int result = 1 ;
		result = 31 * result + ( name == null ? 0 : name.hashCode() );
		result = 31 * result + age ;
		return result ;
	}
	
	@Override
	public String toString() {
		return "Dog [name=" + name + ", age=" + age + "]";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

}
